# $Id: Makefile 34 2009-08-15 16:59:02Z vic.fryzel $

DOCDIR = ./doc
SRCDIR = ./src

all: source

source:
	cd $(SRCDIR); make

dist: doc
	cd $(SRCDIR); make dist

doc:
	cd $(DOCDIR); make

clean:
	cd $(SRCDIR); make clean
	cd $(DOCDIR); make clean

test: test-interpreter test-compiler # test-vm

test-interpreter: source
	@echo; \
	tput sgr0; \
	echo "Testing Interpreter..."; \
	INTERPRETER_TESTS=`find tests/*.bil`; \
	cd src; \
	for t in $$INTERPRETER_TESTS; do \
		diff=`(cat ../$$t | java interpreter.Interpreter) | diff -b -B ../$${t}.interpreter.out -`; \
		tput sgr0; \
		if [ -n "$$diff" ]; \
		then \
			echo -ne "\E[31;40m"; \
			echo "$${t} FAILURE"; \
			echo "$${diff}"; \
			tput sgr0; \
		else \
			echo -ne "\E[32;40m"; \
			echo "$${t} SUCCESS"; \
			tput sgr0; \
		fi; \
	done; \
	cd ..; \
	echo

test-compiler: source
	@echo "Testing Compiler..."; \
	COMPILER_TESTS=`find tests/*.bil`; \
	cd src; \
	for t in $$COMPILER_TESTS; do \
		diff=`(cat ../$$t | java compiler.Compiler) | diff -b -B ../$${t}.compiler.out -`; \
		tput sgr0; \
		if [ -n "$$diff" ]; \
		then \
			echo -ne "\E[31;40m"; \
			echo "$${t} FAILURE"; \
			echo "$${diff}"; \
			tput sgr0; \
		else \
			echo -ne "\E[32;40m"; \
			echo "$${t} SUCCESS"; \
			tput sgr0; \
		fi; \
	done; \
	cd ..; \
	echo

test-vm: source
	@echo "Testing VM..."; \
	VM_TESTS=`find tests/*.bil`; \
	cd src; \
	for t in $$VM_TESTS; do \
		cat ../$$t | java compiler.Compiler > ../$${t}.vm.tmp.out; \
		diff=`js vm/VM.js ../$${t}.vm.tmp.out | diff -b -B ../$${t}.interpreter.out -`; \
		rm -f ../$${t}.vm.tmp.out; \
		tput sgr0; \
		if [ -n "$$diff" ]; \
		then \
			echo -ne "\E[31;40m"; \
			echo "$${t} FAILURE"; \
			echo "$${diff}"; \
			tput sgr0; \
		else \
			echo -ne "\E[32;40m"; \
			echo "$${t} SUCCESS"; \
			tput sgr0; \
		fi; \
	done; \
	echo
